package tech.wisefin.track.session;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 用户行为的片段
 * <p>
 * 前端是如果使用的服务器是端渲染，用户的行为会在多个视频片段中
 * 相互时间使用session进行关联，但最后需要合并显示
 */
@Data
@Entity
@Table(name = "session_track_fragments")
@EntityListeners(AuditingEntityListener.class)
public class SessionTrackFragment implements Serializable {

    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    private String id;

    @Column(name = "events", columnDefinition = "TEXT")
    @Convert(converter = JSONArrayConverter.class)
    private JSONArray events;

    @Column(name = "data", columnDefinition = "TEXT")
    @Convert(converter = JSONObjectConverter.class)
    private JSONObject data;

    @Column(name = "width")
    private Integer width;

    @Column(name = "height")
    private Integer height;

    @CreatedDate
    @JsonProperty("created_at")
    @Column(name = "created_at", nullable = false)
    private Date createdAt;
}
